package com.metaverse.backend.converter;

import com.alibaba.fastjson.JSON;
import com.metaverse.backend.domain.FileObject;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter
public class FileObjectConverter implements AttributeConverter<FileObject, String> {
    @Override
    public String convertToDatabaseColumn(FileObject fileObject) {
        if (fileObject != null  )
            return JSON.toJSONString(fileObject);
        return null;
    }

    @Override
    public FileObject convertToEntityAttribute(String s) {
        if (StringUtils.isNotEmpty(s)) {
            return JSON.parseObject(s, FileObject.class);
        }
        return null;
    }
}
